﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utils.App
{
    public class Timer
    {
        /*
         * Fields
         */
        float total;
        float current;

        /*
         * Properties
         */
        public float Total
        {
            get { return total;}

            set
            {
                total = value;
                if (current > total)
                {
                    current = total;
                }
            }
        }

        public float Current
        {
            get { return current; }

            set
            {
                current = value;
                if (current > total)
                {
                    current = total;
                }
            }
        }

        public float Passed { get { return total - current; } }
        public float PassedInPer { get { return (total - current) / total; } }

        /*
         * Methods
         */
        public Timer()
        {
        }

        public Timer(float time)
        {
            Set(time);
        }

        public void Set(float time)
        {
            total = current = time;
        }

        public static implicit operator Timer(float time)
        {
            return new Timer(time);
        }

        public void Update(float dTime)
        {
            current -= dTime;
            if (current < 0)
            {
                current = 0;
            }
        }

        public bool Timeout()
        {
            return current <= 0;
        }
    }
}
